<?php
/**
 * @author Admin
 *
 *
 */
class ImageButton extends HtmlDisplay {
	//TODO - Insert your code here
	protected $id; 
	
	protected $exec;
	
	protected $url;
	
	protected $altgraphic;
	/**
	 *
	 */
	

	public function __construct( $id,$src,$url='',$exec='',$altgraphic='',$class='',$tooltip) {
		parent::__construct();
		$this->id = $id;
		$this->exec = $exec;
		$this->url =$url;
		$this->dat = $this->HtmlElement('a','',array('id'=>$this->id,'class'=> $class,'title'=>$tooltip) );
		$img = $this->HtmlElement('img','',array('src'=>$src) );
		if(!empty($this->url) ){
			$this->dat->addAttribute('href', $this->url);
		}
		$img->addAttribute('id', 'img'.$this->id);
		if(!empty($this->exec)){
			$this->addJSInit( 
			"$(document).ready( function() {
				$(\"#img$id\").click(function(e){
				$this->exec
				return false;
				});
			 });" 
			);
		}
		$this->altgraphic;
		if(!empty( $altgraphic ) ){
			$this->addJSInit( 
			"$(document).ready( function() {
				$(\"#img$id\").mouseover( function(){
					this.src = '$altgraphic';
				} );
				$(\"#img$id\").mouseout( function(){
					this.src = '$src';
				} );
				$(\"#img$id\").css(\"cursor\",\"pointer\");
			 });" 
			);
		}
		$this->dat = $this->dat->addChild($img);
	}
	/**
	 * 
	 * (non-PHPdoc)
	 * @see HtmlDisplay::finalize()
	 */
	public function finalize(){
		$this->output = (string)$this->cleanseXMLString($this->dat->asXML());
	}
	
}


?>